﻿//==================================================================
// Copyright (C) 2011 深圳市中旭企业管理股份有限公司
// 文件名: CrmDeliverHr.cs
// 作 者：代码自动生成
// 日 期：2012-11-13 15:20:24
// 描 述：
// 版 本：1.00
// 修改历史纪录
// 版 本  修改时间      修改人            修改内容
// 1.00             
//==================================================================
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using System.Text;
using Csla;
using lite;
using Csla.Validation;
using Csla.Data;
using System.Data.SqlClient;
using ZX.DAL;
using OpenExpressApp.ORM;

namespace ZX.CRM.Library
{
    /// <summary>
    /// 
    /// </summary>
    [Serializable]
    [Table(Name = "CrmDeliverHr")]
    [ZX.DBModule.Table("CrmDeliverHr", "ID")]
    public class CrmDeliverHr : ZX.DBModule.BaseEntity
    {

        #region Business Methods 业务方法

        /// <summary>
        /// 主键ID
        /// </summary>
        private static PropertyInfo<Guid> IDProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("ID"));
        [DataObjectField(true, true)]
        [Column, PK]
        public Guid ID
        {
            get { return GetProperty(IDProperty); }
            set { SetProperty(IDProperty, value); }
        }

        /// <summary>
        /// 编码，单号
        /// </summary>
        private static PropertyInfo<string> CodeProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("Code"));
        [Column]
        public string Code
        {
            get { return GetProperty(CodeProperty); }
            set { SetProperty(CodeProperty, value); }
        }
        /// <summary>
        /// 订单产品ID
        /// </summary>
        private static PropertyInfo<Guid> OrderProductIDProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("OrderProductID"));
        [Column]
        public Guid OrderProductID
        {
            get { return GetProperty(OrderProductIDProperty); }
            set { SetProperty(OrderProductIDProperty, value); }
        }
        /// <summary>
        /// 期数ID
        /// </summary>
        private static PropertyInfo<Guid> TermIdProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("TermId"));
        [Column]
        public Guid TermId
        {
            get { return GetProperty(TermIdProperty); }
            set { SetProperty(TermIdProperty, value); }
        }
        /// <summary>
        /// 课中服务人ID
        /// </summary>
        private static PropertyInfo<Guid> ClassFrontServerProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("ClassFrontServer"));
        [Column]
        public Guid ClassFrontServer
        {
            get { return GetProperty(ClassFrontServerProperty); }
            set { SetProperty(ClassFrontServerProperty, value); }
        }
        /// <summary>
        /// 客户经理电话号码
        /// </summary>
        private static PropertyInfo<string> MgrTelProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("MgrTel"));
        [Column]
        public string MgrTel
        {
            get { return GetProperty(MgrTelProperty); }
            set { SetProperty(MgrTelProperty, value); }
        }
        /// <summary>
        /// 接洽人
        /// </summary>
        private static PropertyInfo<string> ConsultPersonProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("ConsultPerson"));
        [Column]
        public string ConsultPerson
        {
            get { return GetProperty(ConsultPersonProperty); }
            set { SetProperty(ConsultPersonProperty, value); }
        }
        /// <summary>
        /// 接洽人电话
        /// </summary>
        private static PropertyInfo<string> ConsultPersonTelProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("ConsultPersonTel"));
        [Column]
        public string ConsultPersonTel
        {
            get { return GetProperty(ConsultPersonTelProperty); }
            set { SetProperty(ConsultPersonTelProperty, value); }
        }
        /// <summary>
        /// 公司邮箱
        /// </summary>
        private static PropertyInfo<string> EmailProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("Email"));
        [Column]
        public string Email
        {
            get { return GetProperty(EmailProperty); }
            set { SetProperty(EmailProperty, value); }
        }
        /// <summary>
        /// 是否成交过鹰计划
        /// </summary>
        private static PropertyInfo<string> IsDealEPProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("IsDealEP"));
        [Column]
        public string IsDealEP
        {
            get { return GetProperty(IsDealEPProperty); }
            set { SetProperty(IsDealEPProperty, value); }
        }
        /// <summary>
        /// 备注
        /// </summary>
        private static PropertyInfo<string> ExplainProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("Explain"));
        [Column]
        public string Explain
        {
            get { return GetProperty(ExplainProperty); }
            set { SetProperty(ExplainProperty, value); }
        }
        /// <summary>
        /// 班主任 多用户ID
        /// </summary>
        private static PropertyInfo<string> PTeacherProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("PTeacher"));
        [Column]
        public string PTeacher
        {
            get { return GetProperty(PTeacherProperty); }
            set { SetProperty(PTeacherProperty, value); }
        }
        /// <summary>
        /// 开课日期
        /// </summary>
        private static PropertyInfo<DateTime> BeginDateProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<DateTime>("BeginDate"));
        [Column]
        public DateTime BeginDate
        {
            get { return GetProperty(BeginDateProperty); }
            set { SetProperty(BeginDateProperty, value); }
        }
        /// <summary>
        /// 班主任手机
        /// </summary>
        private static PropertyInfo<string> GangerTelProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("GangerTel"));
        [Column]
        public string GangerTel
        {
            get { return GetProperty(GangerTelProperty); }
            set { SetProperty(GangerTelProperty, value); }
        }
        /// <summary>
        /// 班号
        /// </summary>
        private static PropertyInfo<string> ClassNoProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("ClassNo"));
        [Column]
        public string ClassNo
        {
            get { return GetProperty(ClassNoProperty); }
            set { SetProperty(ClassNoProperty, value); }
        }
        /// <summary>
        /// 申请人用户ID
        /// </summary>
        private static PropertyInfo<Guid> ApplicantUserProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("ApplicantUser"));
        [Column]
        public Guid ApplicantUser
        {
            get { return GetProperty(ApplicantUserProperty); }
            set { SetProperty(ApplicantUserProperty, value); }
        }
        /// <summary>
        /// 申请日期
        /// </summary>
        private static PropertyInfo<DateTime> ApplicantDateProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<DateTime>("ApplicantDate"));
        [Column]
        public DateTime ApplicantDate
        {
            get { return GetProperty(ApplicantDateProperty); }
            set { SetProperty(ApplicantDateProperty, value); }
        }
        /// <summary>
        /// 添加人ID
        /// </summary>
        private static PropertyInfo<Guid> AddUserProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("AddUser"));
        [Column]
        public Guid AddUser
        {
            get { return GetProperty(AddUserProperty); }
            set { SetProperty(AddUserProperty, value); }
        }
        /// <summary>
        /// 添加日期
        /// </summary>
        private static PropertyInfo<DateTime> AddTimeProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<DateTime>("AddTime"));
        [Column]
        public DateTime AddTime
        {
            get { return GetProperty(AddTimeProperty); }
            set { SetProperty(AddTimeProperty, value); }
        }
        /// <summary>
        /// 状态
        /// </summary>
        private static PropertyInfo<Guid> DliverStateProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<Guid>("DliverState"));
        [Column]
        public Guid DliverState
        {
            get { return GetProperty(DliverStateProperty); }
            set { SetProperty(DliverStateProperty, value); }
        }
        /// <summary>
        /// 流程ID
        /// </summary>
        private static PropertyInfo<string> WorkFlowIdProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("WorkFlowId"));
        [Column]
        public string WorkFlowId
        {
            get { return GetProperty(WorkFlowIdProperty); }
            set { SetProperty(WorkFlowIdProperty, value); }
        }
        /// <summary>
        /// 流程实例ID
        /// </summary>
        private static PropertyInfo<string> WorkFlowInsIdProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("WorkFlowInsId"));
        [Column]
        public string WorkFlowInsId
        {
            get { return GetProperty(WorkFlowInsIdProperty); }
            set { SetProperty(WorkFlowInsIdProperty, value); }
        }
        /// <summary>
        /// 任务ID
        /// </summary>
        private static PropertyInfo<string> WorkTaskIdProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("WorkTaskId"));
        [Column]
        public string WorkTaskId
        {
            get { return GetProperty(WorkTaskIdProperty); }
            set { SetProperty(WorkTaskIdProperty, value); }
        }
        /// <summary>
        /// 任务实例ID
        /// </summary>
        private static PropertyInfo<string> WorkTaskInsIdProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("WorkTaskInsId"));
        [Column]
        public string WorkTaskInsId
        {
            get { return GetProperty(WorkTaskInsIdProperty); }
            set { SetProperty(WorkTaskInsIdProperty, value); }
        }
        /// <summary>
        /// 学员列表
        /// </summary>
        private static PropertyInfo<string> StudentListProperty = RegisterProperty(typeof(CrmDeliverHr), new PropertyInfo<string>("StudentList"));
        public string StudentList
        {
            get { return GetProperty(StudentListProperty); }
            set { SetProperty(StudentListProperty, value); }
        }
        #endregion

        #region Validation Rules 验证规则
        //将验证规则与业务对象的属性联系在一起
        protected override void AddBusinessRules()
        {
            //AddRule的第一个参数是委托变量，也就是说是方法的变量
            ValidationRules.AddRule(CommonRules.StringRequired, "Code");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Code", 10));
            ValidationRules.AddRule(CommonRules.StringRequired, "MgrTel");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("MgrTel", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ConsultPerson");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsultPerson", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ConsultPersonTel");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ConsultPersonTel", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "Email");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Email", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "IsDealEP");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("IsDealEP", 1));
            ValidationRules.AddRule(CommonRules.StringRequired, "Explain");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("Explain", 200));
            ValidationRules.AddRule(CommonRules.StringRequired, "PTeacher");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("PTeacher", 500));
            ValidationRules.AddRule(CommonRules.StringRequired, "GangerTel");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("GangerTel", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "ClassNo");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("ClassNo", 30));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkFlowInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkFlowInsId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskId", 50));
            ValidationRules.AddRule(CommonRules.StringRequired, "WorkTaskInsId");
            ValidationRules.AddRule(CommonRules.StringMaxLength, new Csla.Validation.CommonRules.MaxLengthRuleArgs("WorkTaskInsId", 50));
            //base.AddBusinessRules();
        }
        #endregion

        #region Factory Methods 工厂方法

        public CrmDeliverHr() { }

        public static CrmDeliverHr New()
        {
            return DataPortal.Create<CrmDeliverHr>();
        }
        public static CrmDeliverHr Get(Guid ID)
        {
            return DataPortal.Fetch<CrmDeliverHr>(new SingleLazyCriteria<CrmDeliverHr, Guid>(ID, false));
        }
        public static void Delete(Guid ID)
        {
            DataPortal.Delete(ID);
        }

        //public override CrmDeliverHr Save()
        //{
        //return base.Save();
        //}
        #endregion

        #region Data Access 数据访问
        //由于DataPortal_create中没有对数据库的访问，所有标记了Runlocal特性，使得该方法只需在本地运行即可
        //如果代码中有访问数据库的方法，那么就不要用这个特性，使数据门户可以根据情况将此方法的运行选择在应用服务器还是本地
        [RunLocal()]
        protected override void DataPortal_Create()
        {
            //在此调用CheckRules对所有的属性进行验证规则的检查，这样检查只运行一次。
            ValidationRules.CheckRules();
        }


        //可以看到此方法没有标记任何特性
        //此方法要访问数据库所以不能标记本地，由于她没有任何数据库更新操作所以也无需事务性的保护
        //此方法调用结束后会隐含的调用MarkOld（）方法
        private void DataPortal_Fetch(Guid ID)
        {
            //通过连接字符串建立SQL连接对象，Using符号代表，范围释放的意思，SqlConnection对象会在此范围后被释放掉
            using (var ctx = ConnectionManager<SqlConnection>.GetManager(ConnectionStringNames))
            {
                IDb db = DbFactory.Instance.GetDb(ctx.Connection);
                IQuery q = db.Query();
                q.Constrain("ID").Equal(ID);
                var data = db.Select<CrmDeliverHr>(q)[0];
                LoadProperty(IDProperty, data.ID);
                LoadProperty(CodeProperty, data.Code);
                LoadProperty(OrderProductIDProperty, data.OrderProductID);
                LoadProperty(ClassFrontServerProperty, data.ClassFrontServer);
                LoadProperty(MgrTelProperty, data.MgrTel);
                LoadProperty(ConsultPersonProperty, data.ConsultPerson);
                LoadProperty(ConsultPersonTelProperty, data.ConsultPersonTel);
                LoadProperty(EmailProperty, data.Email);
                LoadProperty(IsDealEPProperty, data.IsDealEP);
                LoadProperty(ExplainProperty, data.Explain);
                LoadProperty(PTeacherProperty, data.PTeacher);
                LoadProperty(BeginDateProperty, data.BeginDate);
                LoadProperty(GangerTelProperty, data.GangerTel);
                LoadProperty(ClassNoProperty, data.ClassNo);
                LoadProperty(ApplicantUserProperty, data.ApplicantUser);
                LoadProperty(ApplicantDateProperty, data.ApplicantDate);
                LoadProperty(AddUserProperty, data.AddUser);
                LoadProperty(AddTimeProperty, data.AddTime);
                LoadProperty(DliverStateProperty, data.DliverState);
                LoadProperty(WorkFlowIdProperty, data.WorkFlowId);
                LoadProperty(WorkFlowInsIdProperty, data.WorkFlowInsId);
                LoadProperty(WorkTaskIdProperty, data.WorkTaskId);
                LoadProperty(WorkTaskInsIdProperty, data.WorkTaskInsId);
                LoadProperty(StudentListProperty, data.StudentList);
                LoadProperty(TermIdProperty, data.TermId);
            }
        }

        [Transactional(TransactionalTypes.TransactionScope)]
        protected override void DataPortal_DeleteSelf()
        {
            //依然是调用下面的方法删除的，只是他此时可以获得自己的Id
            DataPortal_Delete(IDProperty);
        }
        #endregion

    }
}